<?php

	class Upload{
		
		private $file;	//文件框名称
		private $extArr=array('.jpg','.jpeg','.gif','.png','.zip','.rar');
		public $filePath;	//文件所在路径
		
		public function __construct($file){
			$this->file=$file;	//为文件框名称赋值
		}
		
		public function up($path){
			$extname=strrchr($_FILES[$this->file]['name'],'.');	//文件括展名
			if(!in_array(strtolower($extname),$this->extArr)){
				return 1;
			}
			$size=$_FILES[$this->file]['size'];
			if($size>2000000){
				return 2;
			}
			//生成文件名
			$_path=$path.'/'.date('Ym');
			if(!file_exists($_path)){
				mkdir($_path);
			}
			$_filename=date('Ym').'/'.time().$extname;
			$filename=$path.'/'.$_filename;
			if(file_exists($filename)){
				return 4;
			}
			$this->filePath=$filename;	//文件所在真实路径
			//复制文件
			copy($_FILES[$this->file]['tmp_name'],$filename);
			return $_filename;
		}
		
		
	}
?>